<?php


namespace app\api\controller;
use app\api\model\Banner as BannerModel;

class Banner extends Controller
{
    public function uploads(){
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('image');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->move( '../public/uploads/banner');
        if($info){
            // 成功上传后 获取上传信息
            $_POST = 'http://audio.com:8088/service/public/uploads/banner/'.$info->getSaveName();
            echo $_POST;
        }else{
            // 上传失败获取错误信息
            echo $file->getError();
        }
    }
    public function getBanner(){
        $model=new BannerModel();
        $banner=$model->select();
        //dump($news);
        return $this->renderSuccess($banner,'获取banner成功');

    }
    public function addBanner($imageUrl){
        $model=new BannerModel();
        $model->url= $imageUrl;
        if ($model->save()) {
            $new_banner = $model->where(['baneerid' => $model->getLastInsID()])->find();
            return $this->renderSuccess($new_banner, '添加成功');
        } else {
            return $this->renderError('添加失败');
        }

    }
}
